<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const arr =[8,2,6,5,4,1,3]
    const num = 7
   function f(res){
    const arr = res.toString().split('').reverse()
    console.log(arr)
    const arr2 = []
    arr.forEach((ele,index) => {
      arr2.push(ele)
      if(index % 3 === 2){
        arr2.push(',')
      }
    })
    const arr3 = arr2.reverse()
    if(arr3[0] == ','){
      arr3.shift()
    }
    return arr3.join('')
   }
   f(num)
  </script>
</body>
</html>